package com.zsw.dubbo.filter;


import java.util.HashMap;
import java.util.Map;

import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcInvocation;

public class ConsumerFilter implements Filter  {
	
	public static String username = "admin";
	public static String password = "admin0";

	public Result invoke(Invoker<?> invoker, Invocation invocation)
			throws RpcException {
		Map<String, String> map = invocation.getAttachments();
		if(map == null){
			map = new HashMap<String, String>();
		}
		map.put("username", username);
		map.put("password", password);
		if(invocation.getAttachments() == null){
			return invoker.invoke(new RpcInvocation(invocation.getMethodName(),invocation.getParameterTypes(),
					invocation.getArguments(),map,invoker));
		}
		return invoker.invoke(invocation);
	}
}
